package com.ruoyi.web.controller.gxs;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gxs.domain.GxsYearname;
import com.ruoyi.gxs.service.IGxsYearnameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学期名称Controller
 * 
 * @author 高晓松
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/gxs/yearname")
public class GxsYearnameController extends BaseController
{
    @Autowired
    private IGxsYearnameService gxsYearnameService;

    /**
     * 查询学期名称列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:list')")
    @PreAuthorize("@ss.hasAnyRoles('class,admin,student,common')")
    @GetMapping("/list")
    public TableDataInfo list(GxsYearname gxsYearname)
    {
        startPage();
        List<GxsYearname> list = gxsYearnameService.selectGxsYearnameList(gxsYearname);
        return getDataTable(list);
    }

    /**
     * 导出学期名称列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:export')")
    @Log(title = "学期名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxsYearname gxsYearname)
    {
        List<GxsYearname> list = gxsYearnameService.selectGxsYearnameList(gxsYearname);
        ExcelUtil<GxsYearname> util = new ExcelUtil<GxsYearname>(GxsYearname.class);
        util.exportExcel(response, list, "学期名称数据");
    }

    /**
     * 获取学期名称详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:query')")
    @GetMapping(value = "/{gxsYearid}")
    public AjaxResult getInfo(@PathVariable("gxsYearid") Long gxsYearid)
    {
        return success(gxsYearnameService.selectGxsYearnameByGxsYearid(gxsYearid));
    }

    /**
     * 新增学期名称
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:add')")
    @Log(title = "学期名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxsYearname gxsYearname)
    {
        return toAjax(gxsYearnameService.insertGxsYearname(gxsYearname));
    }

    /**
     * 修改学期名称
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:edit')")
    @Log(title = "学期名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxsYearname gxsYearname)
    {
        return toAjax(gxsYearnameService.updateGxsYearname(gxsYearname));
    }

    /**
     * 删除学期名称
     */
//    @PreAuthorize("@ss.hasPermi('gxs:yearname:remove')")
    @Log(title = "学期名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxsYearids}")
    public AjaxResult remove(@PathVariable Long[] gxsYearids)
    {
        return toAjax(gxsYearnameService.deleteGxsYearnameByGxsYearids(gxsYearids));
    }
}
